<template>
  <div>
      <t-table
        :data="data"
        :columns="COLUMNS"
        row-key="id"
        vertical-align="top"
        :hover="true"
        :pagination="pagination"
        :loading="dataLoading"
        :selected-row-keys="selectedRowKeys"
        @page-change="rehandlePageChange"
      >
        <template #jobStatus="{ row }">
          <t-tag v-if="row.jobStatus === 1" variant="light"> 待完成 </t-tag>
          <t-tag v-if="row.jobStatus === 2" theme="primary" variant="light"> 己完成 </t-tag>
        </template>
        <template #op="slotProps">
          <a class="t-button-link" @click="handleClickDetail(slotProps)">查询结果</a>
        </template>
      </t-table>

  </div>
</template>

<script setup type="ts">
  import { ref,reactive, computed } from 'vue';
  import { useRouter } from 'vue-router';
  import { MessagePlugin } from 'tdesign-vue-next';
  import { getIntegralList } from '@/api/user';
  import { prefix } from '@/config/global';


const COLUMNS=ref([])
COLUMNS.value=[
  // { colKey: 'row-select', type: 'multiple', width: 64, fixed: 'left' },
  // {
  //   title: 'id',
  //   align: 'left',
  //   width: 120,
  //   ellipsis: true,
  //   colKey: 'Id',
  //   //fixed: 'left',
  // },
  {
    title: '日期',
    align: 'left',
    width: 120,
    ellipsis: true,
    colKey: 'CreateDate',
    //fixed: 'left',
  },
  {
    title: '类型',
    align: 'left',
    width: 120,
    ellipsis: true,
    colKey: 'IntegralTypeText',
    //fixed: 'left',
  },

  {
    title: '变更额度',
    align: 'left',
    width: 120,
    ellipsis: true,
    colKey: 'Integral',
    //fixed: 'left',
  },
  {
    title: '变更前额度',
    align: 'left',
    width: 120,
    ellipsis: true,
    colKey: 'BeforeAmount',
    //fixed: 'left',
  },

  {
    title: '变更后额度',
    align: 'left',
    width: 120,
    ellipsis: true,
    colKey: 'AfterAmount',
    //fixed: 'left',
  },


  {
    title: '关联单号',
    align: 'left',
    width: 120,
    ellipsis: true,
    colKey: 'OrderNo',
    //fixed: 'left',
  },

]
const data = ref([]);
const pagination = reactive({
  current: 1,
  pageSize: 20,
  total: 0,
});
const dataLoading = ref(false);
const confirmVisible = ref(false);
const selectedRowKeys = ref([]);
const drawerVisible = ref(false);
const fetchData =  (paginationInfo) => {
  dataLoading.value = true;
  getIntegralList(paginationInfo).then(ret=>{
     const {items,totalItems,currentPage}=ret
     data.value = items;
     pagination.total = totalItems;
     pagination.current = currentPage;

  }).catch(e=>{
    console.log('e  ',JSON.stringify(e))

  }).finally(()=>{
    dataLoading.value = false;
  })

};
fetchData({
    page: pagination.current,
    pageSize: pagination.pageSize,
  });
// 刷新数据
const refresh = async () => {
  pagination.current = 1;
  await fetchData(pagination);
};
const rehandlePageChange = (pageInfo) => {
  console.log(`rehandlePageChange${JSON.stringify(pageInfo)}`);
  pagination.current = pageInfo.current;
  pagination.pageSize = pageInfo.pageSize;
  fetchData({page:pageInfo.current,pageSize:pageInfo.pageSize});
};

</script>
